package com.Gosposia;

import CLIPSJNI.*;

public class ClipsParser
{
	private Environment clips;
	private String czynnosc, cel;
	
	public ClipsParser (String path)
	{
		clips = new Environment();
		clips.load(path);
	}
	
	public void DodajFakt(String fakt)
	{
		clips.assertString(fakt);
	}
	
	public void Reset()
	{
		clips.reset();
	}
	
	public void Run()
	{
		clips.run();
		
		setCzynnosc("");
		
		String evalString = "(find-all-facts ((?f decyzja)) TRUE)";
		try {
			
		int liczba = clips.eval(evalString).size();
		if(liczba == 0)
		{
			return;
		}
		PrimitiveValue pv = clips.eval(evalString).get(0);
		
		
		setCzynnosc(pv.getFactSlot("czynnosc").toString());
		setCel(pv.getFactSlot("cel").toString());
		
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void Clear()
	{
		clips.clear();
	}
	
	public void Destroy()
	{
		clips.destroy();
	}

	public String getCzynnosc() {
		return czynnosc;
	}

	public void setCzynnosc(String czynnosc) {
		this.czynnosc = czynnosc;
	}

	public String getCel() {
		return cel;
	}

	public void setCel(String cel) {
		this.cel = cel;
	}
}
